package com.hyperf.core.exception;

import lombok.Getter;
import lombok.Setter;

/**
 * 自定义异常类
 *
 * @author lizhaoyang
 * @date 2020/11/30
 */
@Getter
@Setter
public class CustomException extends RuntimeException {

    private static final long serialVersionUID = -1851967442680844269L;

    private int errorCode;

    private String errorMessage;

    public CustomException() {
        super();
    }

    public CustomException(String errorMessage) {
        super(errorMessage);
        this.errorMessage = errorMessage;
    }

    public CustomException(int errorCode, String errorMessage) {
        this(errorMessage);
        this.errorCode = errorCode;
    }

    public CustomException(ExceptionInfo exceptionInfo) {
        this(exceptionInfo.getErrorCode(), exceptionInfo.getErrorMessage());
    }

    public CustomException(Throwable throwable) {
        this(throwable.getMessage());
    }

    @Override
    public String toString() {
        return this.errorCode + ":" + this.errorMessage;
    }
}
